import api from '../index'
import type { ResponseData, PagingData, pageParam,RequestFromType } from '../index'
import type {PreviewOrderData,PurchaseGoodsPayData} from '.'

//获取拼团规则
export const getActivityGroupRule = () =>
	api.get<ResponseData<{ruleState : number,ruleMsg : string}>>('customer/api/activity/group/rule', {
		custom: {
			auth: false
		}
	})
export interface GroupGoodsItem {
	buyStock : number
	coverImg : string
	createTime : string
	id : number
	oldPrice : number
	peopleNumber : number
	peopleState : number
	price : number
	productId : string
	productName : string
	shamStock : number
	skuId : string
	skuName : string
	stock : number
	storeId : string
	timeLimit : number
}
// 拼团商品列表
export const getActivityGroupList = (data : pageParam) =>
	api.get<ResponseData<PagingData<GroupGoodsItem>>>('customer/api/activity/group/list',
		{
			data,
			custom: {
				auth: false
			}
		}
	)
export interface PurchaseGroupGoodsParams {
	receivedId ?: number | string
	receivingType?: string
	qty : string
	skuId : string
	remark ?: string
	fromType ?: RequestFromType,
	payId : number
	payword ?: string
	traceId?:string
}
// 开启拼团
export const createOrderGroup = (data:PurchaseGroupGoodsParams) =>
	api.post<PurchaseGoodsPayData>('customer/api/order/group/create',
		{
			data
		}
	)
export interface PreviewGroupGoodsOrderParams {
	receivedId ?: number | string
	receivingType?: string
	qty : string
	skuId : string
}

export interface PreviewGroupOrderData extends PreviewOrderData {
	orderGroup?:GroupByPayData
}
// 拼团预览
export const previewOrderGroup = (data:PreviewGroupGoodsOrderParams) =>
	api.post<ResponseData<PreviewGroupOrderData>>('customer/api/order/group/create/one/pre',
		{
			data
		}
	)
export interface OrderGroupItem {
	userPhoto ?: string
	userNickname ?: string
	groupNum : number
	nowNum : number
}

// 查询一个商品的正在拼团列表
export const getOrderGroupList = (data : pageParam & { commodityId : string }) =>
	api.get<ResponseData<PagingData<OrderGroupItem>>>('order/api/group/list', {
		data
	})
export interface GroupByPayData {
	state:number
	groupCode:string
	overTime:string
	groupNum:number
	deputy:Array<{
		commodityUrl:string
		commodityName:string
		deputyMoney:number
		name:string
		shareMsg:string
	}>
	headUrls:string[]
	nowNum?:number
	
}
// 根据支付单号查询拼团信息
export const getGroupByPayCode = (data:{payCode:string}) =>
	api.get<ResponseData<GroupByPayData>>('order/api/group/payCode', {
		data
	})